Strict
Import mojo
Import agfx

Class TGUIButton

	Field name:String
	Field enable:Bool
	Field img_btn:TSprite
	Field OnHit:TCallback


	Method New(name:String,img_skin:String,x:Int,y:Int,enable:Bool)

	
		Self.name = name
		Self.enable = enable
		Self.img_btn = New TSprite(name,IMAGES.Find(img_skin),x,y)
		
		Self.img_btn.SetFrame(2)

		if Self.enable Then
			Self.img_btn.SetAlpha(1)
		else
			Self.img_btn.SetAlpha(0.5)
		End
	End

	Method Update:Void()
	
		
		
		Self.img_btn.Update()
		Self.img_btn.SetFrame(0)
		
		If Self.IsMouseInside() Then
		
		#If TARGET="android" Or TARGET="ios" Then
			' none
		#Else
			Self.img_btn.SetFrame(2)
		#End
		
			If MOUSE.Hit() Then
				Self.img_btn.SetFrame(1)
				Self.OnHit.Call()
			End
		End

	End

	Method Draw:Void()
		Self.img_btn.Draw()	
		
		If DEBUG Then
			DrawRectOutline(	Self.img_btn.position.x-Self.img_btn.bitmap.image.HandleX(),
								Self.img_btn.position.y-Self.img_btn.bitmap.image.HandleY(),
								Self.img_btn.bitmap.image.Width(),
								Self.img_btn.bitmap.image.Height())
		EndIf
	End

	'|---------------------------------------------------------------------------------------
	'| PRIVATE METHODS
	'|---------------------------------------------------------------------------------------	
	Private
	
	Method IsMouseInside:Bool()
	
		Local x1:Int = Self.img_btn.position.x-Self.img_btn.bitmap.image.HandleX()
		Local y1:Int = Self.img_btn.position.y-Self.img_btn.bitmap.image.HandleY()
		
		Local x2:Int = x1 + Self.img_btn.bitmap.image.Width()
		Local y2:Int = y1 + Self.img_btn.bitmap.image.Height()
		
		
		If (MOUSE.x >= x1) And 
		   (MOUSE.x <= x2) And 
		   (MOUSE.y >= y1) And 
		   (MOUSE.y <= y2) Then
			Return True
		Else
			Return False
		End If
		
		Return False
		
	End Method
End




